<template>
	<section>
		<el-tabs v-model="activeName" @tab-click="handleClick">
			<el-tab-pane label="驾驶员基础信息" name="first">
				<el-form :label-position="labelPosition" label-width="100px">
					<el-row type="flex" justify="center" :gutter="50">
						<el-col :span="10">
							<el-form-item label="姓名:">
								<el-input placeholder="请输入"></el-input>
							</el-form-item>
							<el-form-item label="身份证号:">
								<el-input placeholder="请输入"></el-input>
							</el-form-item>
							<el-form-item label="保险信息:">
								<el-input placeholder="请输入"></el-input>
							</el-form-item>
							<el-form-item label="备注:">
								<el-input type="textarea" placeholder="请输入备注..."></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="10">
							<el-form-item label="联系方式:">
								<el-input placeholder="请输入"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
				<el-row type="flex">
					<el-col :span="4" v-for="fit in fits" :key="fit" :offset="3">
						<span class="title">{{ fit }}</span>
						<el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
							:show-file-list="false" :on-success="handleAvatarSuccess"
							:before-upload="beforeAvatarUpload">
							<img v-if="imageUrl" :src="imageUrl" class="avatar">
							<i v-else class="el-icon-plus avatar-uploader-icon"></i>
						</el-upload>
					</el-col>
				</el-row>
				<el-row class="cares">
					<el-col :span="21" :offset="3">
						<span class="title">保险单：</span>
						<!-- <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
							:show-file-list="false" :on-success="handleAvatarSuccess"
							:before-upload="beforeAvatarUpload">
							<img v-if="imageUrl" :src="imageUrl" class="avatar">
							<i v-else class="el-icon-plus avatar-uploader-icon"></i>
						</el-upload> -->
						<el-upload action="https://jsonplaceholder.typicode.com/posts/" list-type="picture-card"
							:on-preview="handlePictureCardPreview" :on-remove="handleRemove">
							<i class="el-icon-plus"></i>
						</el-upload>
						<el-dialog :visible.sync="dialogVisible">
							<img width="100%" :src="dialogImageUrl" alt="">
						</el-dialog>
					</el-col>
				</el-row>
				<el-row class="btnbox">
					<el-col :span="6" :offset="3">
						<el-button type="primary">提交</el-button>
						<el-button>取消</el-button>
					</el-col>
				</el-row>
			</el-tab-pane>
		</el-tabs>
	</section>
</template>

<script>
	export default {
		data() {
			return {
				labelPosition: 'right',
				activeName: 'first',
				fits: ['驾驶证：', '身份证正面：', '身份证反面：', '其他：'], //驾驶员基础信息
				boxs: ['保险单：'], //保险单				
				imageUrl: '', //上传照片	
				dialogImageUrl: '',
				dialogVisible: false
			}
		},
		methods: {
			handleClick(tab, event) {
				console.log(tab, event);
			},
			handleAvatarSuccess(res, file) {
				this.imageUrl = URL.createObjectURL(file.raw);
			},
			beforeAvatarUpload(file) {
				const isJPG = file.type === 'image/jpeg';
				const isLt2M = file.size / 1024 / 1024 < 2;

				if (!isJPG) {
					this.$message.error('上传头像图片只能是 JPG 格式!');
				}
				if (!isLt2M) {
					this.$message.error('上传头像图片大小不能超过 2MB!');
				}
				return isJPG && isLt2M;
			},
			// 保险单多图上传
			handleRemove(file, fileList) {
				console.log(file, fileList);
			},
			handlePictureCardPreview(file) {
				this.dialogImageUrl = file.url;
				this.dialogVisible = true;
			}

		}
	}
</script>
<style>
	.title {
		padding: 0 0 10px;
		display: block;
	}

	.avatar-uploader .el-upload {
		border: 1px dashed #a7a3a3;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #d5d7da;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}

	.btnbox {
		padding: 50px 0 30px;
	}

	.el-date-editor.el-input {
		width: 100%;
	}
	
	.cares{
		padding:20px 0 0;
	}
</style>
